package vip.geeker.iotms.scheduled;


import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vip.geeker.iotms.service.impl.DeviceService;
import vip.geeker.iotms.utils.ObjectUtils;
import vip.geeker.iotms.utils.RedisUtils;

import javax.annotation.Resource;
import java.util.Map;

@Component
@Slf4j
public class ReportOrderTask{

    @Resource
    private DeviceService deviceService;

    /**
     * 每5分钟的执行
     */
    @Scheduled(cron = "0 */5 * * * ?")
    @Async
    public void pullReportOrder() {
        // 获取redis 数据
        /*Map handleData = Maps.newHashMap();
        handleData.put("1", "36|90");
        RedisUtils.setHashMap("NEED_HANDEL_DATA", handleData);*/

        Map<String, String> needHandelData = RedisUtils.getHashMap("NEED_HANDEL_DATA");
        if(ObjectUtils.isNotNullAndEmpty(needHandelData)){
            log.info("~~~~~~~~~~~~~~~~~~~执行解析规则开始~~~~~~~~~~~~~~~~~~~");
            needHandelData.forEach((key,value)->{
                deviceService.analysisData(Integer.valueOf(key),value);
            });
            log.info("~~~~~~~~~~~~~~~~~~~执行解析规则结束~~~~~~~~~~~~~~~~~~~");

        }
    }
}
